Copyright: Visual Help ® 1993-1994 Firas Bushnaq


Contents

Name

grep - search a file or files for a pattern

Description

Grep for Windows searches one or more files for a matching sequence of characters (the search pattern), which is specified as a simple regular expression.  The name of each searched file is displayed in the output window, complete with lines that matched the search pattern (if any).  Optionally, each matching line can be preceded by its line number within the file.

Grep can be invoked either from Program Manager or from the WinXs menu in File Manager.  The extension of the first file selected in the File Manager file window (if any), with the filename part replaced by the "*" wild-card character, is passed to Grep as the name of the file(s) to be searched.  The user must fill in remaining fields of the search dialog box before searching can begin.

See Also

Regular expression

Search Dialog

Menus


Regular Expression

A regular expression is made up of ordinary characters and metacharacters.  An ordinary character matches itself; for example, the re "aardvark" matches the character sequence <a><a><r><d><v><a><r><k> anywhere in an input line.  A metacharacter or metacharacter sequence has special meaning as described below.

Metacharacters

 .	A dot (.) matches any character.  For example, the re "ab." matches the character sequence <a><b><any-character>.

 *	An asterisk (*) matches the previous ordinary character, metacharacter or metacharacter sequence any number of times.  For example, the re "ab.*" matches the character sequence <a><b><any-character...>.

 \	A backslash (\) escapes the following character and is commonly used to escape the meaning of a metacharacter.  For example, the re "ab\." matches the character sequence <a><b><.>.

\n	This expression matches the same string of characters as was matched by the nth expression enclosed between the metacharacter sequence \( and \) (see below for details), appearing earlier in the same regular expression. For example, the re "^\(abc\)\1$" matches a line consisting of two repeated appearances of the string <a><b><c>.

 ^	A caret (^) anchors a regular expression at the start of an input line.  For example, the re "^abc" will only match input lines that start with the character sequence <a><b><c>

 $	A dollar ($) anchors a regular expression at the end of an input line.  For example, the re "abc$" will only match input lines that end with the character sequence <a><b><c>.

\t	(WinXs extension)  A backslash character followed by the letter 't' matches a <tab> character.  This metacharacter is necessary in a Windows environment because a <tab> character cannot be entered directly into a field within a dialog control.

Metacharacter Sequences

 [...]	A bracketed re is a metacharacter sequence that defines a scanset.  A scanset defines single characters or character ranges that are matched against the next character in the input line.  For example, the re "^[abc]" will match any input line that begins with the characters <a>, <b> or <c>.  A character range is denoted by dash (-) separated character sequences; that is, the re "^[a-z]" matches any line beginning with a lower-case letter, the re "^[a-zA-Z]" matches any line beginning with a lower-case or an upper-case letter.  Within scansets, metacharacters, other than a dash, lose their special meaning.  A dash character appearing as the first or last character in a scanset loses its special meaning and matches itself.  A caret (^) appearing as the first character in a scanset causes the scanset to be complemented; that is, the re will match characters NOT specified in the scanset.

\{m,n\}	Is a range expression that matches the previous ordinary character or metacharacter a specified number of times.  The values of m and n must be integers in the range 1-255.  The expression \{m\} matches exactly m occurrences; \{m,\} matches at least m occurrences; \{m,n\} matches any number of occurrences between m and n inclusive.  Wherever a choice exists, the re matches as many occurrences as possible.

\(re\)	An re enclosed between \( and \) matches whatever the unadorned re matches.  However, the enclosed re can also be used for repeating a match (see \n above).


Search Dialog

Filenames

The name of one or more files to be searched.  If DOS wild-card characters are specified, filename expansion will occur automatically.  Multiple filenames appearing in this field should be separated by space characters.

Patterns

Specifies one or more regular expressions separated by newline characters.  Grep will search the specified files for lines that contain (or do not contain) a character sequence matching one of the specified patterns.

Regular Expression

Flags

Specifies the option flags for this search operation.

Option Flags

Directory

Specifies the directory containing the file or files specified by Filenames.  The search directory can be changed by double-clicking a directory name or a drive name in the associated list box.


Option Flags

Ignore Case

The case of characters is ignored during searching.  For example, the letters "A" and "a", "B" and "b", etc. are considered equal.  Thus a search for all words beginning with the letter "A" would match "alpha", "Albert", etc..

Display Line Numbers

Matching lines in the output window will be preceded by their relative line number within the file that contains them.  This is only meaningful for text files.

Descend Subdirectories

If checked, Grep will search the current directory and all its subdirectories for files that match the input filespec or partspec.  Otherwise it will  only check files in the current directory.

Display Unmatched Lines

Normally Grep displays lines that match the specified regular expression.  If this option is checked, however, it displays only those lines that DO NOT match the specified regular expression..


Menus

File Menu:

New

Start another file search

Save As

Save the contents of the output window to a file

View

View selected file.  Select a filename anywhere in the output window (e.g., by double-clicking the left mouse button over the appropriate name) and then select this item to pass the filename to more for viewing.

Print

Print the contents of the output window

Print Preview

Preview print formatting and content

Exit

Terminate Grep for WIndows

Edit Menu:

Copy

Copy current selection to the clipboard

Help Menu:

Contents

Display contents topic of this help file

About

Display program name and version number